package com.tuoyu.peopletest.utils;


import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;

import com.lxj.xpopup.XPopup;
import com.tuoyu.peopletest.R;
import com.tuoyu.peopletest.view.pop.ResultPop;


/**
 * 项目中 一样的UI,多地方使用, 将其抽取成工具类
 */
public class SCBizUIUtils {


    private static SCBizUIUtils  sInstance;
    private SCBizUIUtils() {

    }
    public static SCBizUIUtils get() {
        if (sInstance == null) {
            sInstance = new SCBizUIUtils();
        }
        return sInstance;
    }


    /**
     * 列表的图片, 防止错乱
     */
    public  void setItemIv(Context context, String path, ImageView iv, int nomalRes){
        if (!TextUtils.isEmpty(path)) {

            String imagPath = path;

            String tagPath = (String) iv.getTag(R.id.glide_image_tag);
            if (!path.equals(tagPath)) {
                //iv.setBackgroundResource(nomalRes);
                iv.setImageResource(nomalRes);
                iv.setTag(R.id.glide_image_tag, path);
            }
            SCImageUtils.loadCenterCrop(context, imagPath, iv,nomalRes);
        }
    }

    public  void setItemIv(Context context, int res, ImageView iv, int nomalRes){
        if (res>0&& iv!=null) {


            Integer tagPath = (Integer) iv.getTag(R.id.glide_image_tag);
            if (tagPath != null && res != tagPath ) {
                //iv.setBackgroundResource(nomalRes);
                iv.setImageResource(nomalRes);
                iv.setTag(R.id.glide_image_tag, res);
            }
            SCImageUtils.loadCenterCrop(context, res, iv,nomalRes);
        }
    }

    /**
     * 未找到设备
     */
    public static void showHint(Context context,String hint) {
        new XPopup.Builder(context)
                .dismissOnTouchOutside(false)
                .asCustom(new ResultPop(context,hint))
                .show();
    }
}
